package richbar.com.richbar.help;

import android.app.Activity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import richbar.com.richbar.R;


/**
 * Created by qyang on 2018-3-6.
 */

public class TitleHelp {
    private Activity mActivity;
    private ImageView back;
    private TextView title;
    private TextView right;
    private ImageView right_iv;
    private RelativeLayout back_body;

    public TitleHelp(Activity mActivity) {
        this.mActivity = mActivity;
        initLayout();
    }


    private void initLayout(){
        right = mActivity.findViewById(R.id.right_tv);
        title = mActivity.findViewById(R.id.title);
        back = mActivity.findViewById(R.id.back);
        right_iv = mActivity.findViewById(R.id.right_iv);
    }

    public TitleHelp setTitle(String s){
        title.setText(s);
        onLeft();
        return this;
    }

    public TitleHelp setRightIv(int imgRes, View.OnClickListener listener){
        right_iv.setImageResource(imgRes);
        right_iv.setOnClickListener(listener);
        right_iv.setVisibility(View.VISIBLE);
        return this;
    }

    public TitleHelp setRightTv(String rightTv, View.OnClickListener listener){
        right.setText(rightTv);
        right.setOnClickListener(listener);
        return this;
    }

    public TitleHelp setRightTv(String rightTv){
        right.setText(rightTv);
        return this;
    }

    public TitleHelp setRightGone(){
        right.setVisibility(View.GONE);
        return this;
    }

    private void onLeft(){
        back_body = mActivity.findViewById(R.id.back_body);
        back_body.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.finish();
            }
        });
    }

    public TextView getRight(){
        return right;
    }
}
